/**
 * @作者 xiaohengheng
 * @微信公号 林间有风
 * @开源项目 $ http://7yue.pro
 * @免费专栏 $ http://course.7yue.pro
 * @我的课程 $ http://imooc.com/t/4294850
 */
import api from '../api/index'

class Categories {
  roots = []
  subs = []

  async getAll() {
    const data = await api.get('category/all')
    this.roots = data.roots
    this.subs = data.subs
    return data
  }

  getRoots() {
    return this.roots
  }

  getRoot(rootId) {
    return this.roots.find(r => r.id == rootId)
  }

  getSubs(parentId) {
    return this.subs.filter(sub => sub.parent_id == parentId)
  }
}

export { Categories } 